<?php


namespace App\Http\Controllers\Weapp;

use App\Model\Address;
use App\Model\GoodsSku;
use App\Tool\Json;

class Confirm extends Auth
{


    function getDefaultAddress(){

        $default=[];

        $user_id=resolve('weapp_user')['id'];

        $list=Address::where('user_id',$user_id)->get();

//        dd($list);

        if(!$list->toArray()) return Json::code(2,'success');


        foreach ($list as $key=>$value){

            if($value->is_default==1) return Json::code(1,'success',$value);

        }


        return Json::code(1,'success',$list[0]);

    }

    /**
     * 订单确认页面
     * Create by Peter
     * 2020/06/10 11:02:18
     * Email:904801074@qq.com
     * @return false|string
     */
    function getGoodsDetail(){

        $param=request()->input('param');

        $array=explode('!',$param);

        $goods_info=[];

        foreach ($array as $key=>$value){


            $array_detail=explode('*',$value);

            $sku_id=$array_detail[0];

            $num=$array_detail[1];

            $goods_data=GoodsSku::with('goods')
                ->with('snapped_sku.snapped')
                ->with('goods_sku_detail')->find($sku_id);

            $goods_info[]=['num'=>$num,'detail'=>$goods_data];

        }


        return Json::code(1,'success',$goods_info);


    }

}
